import com.adobe.cairngorm.control.CairngormEventDispatcher;
import net.optix.ip.events.AddClientEvent;
import net.optix.ip.vo.ClientVO; 
import net.optix.ip.model.ModelLocator;
        	
import mx.events.CloseEvent; 
import mx.managers.PopUpManager;
import mx.events.ValidationResultEvent;
            
[Bindable]
private var messageP:String	=	
	'Welcome to IP Manager, where growing businesses manage their intellectual property.<br><br>'+
	'At IP Manager, you can record your ideas, estimate the value of an idea, request bids from law firms for preparing patent applications, and track the application process.<br><br>'+
  	'You have successfully registered your business with this email address as your user id and password same as your email.<br><br>'+
 	'You may login here with the password that you entered during registration.  If you have forgotten your password, you may have a new password sent to you by selecting reset.<br><br>'+
   	'IP Manager does not provide legal services, but can connect you with providers of legal services.  ';
            
[Bindable]
public var model:ModelLocator	=	ModelLocator.getInstance(); 

private function initApp():void
{
	model.result	=	"";
	model.bSubmit	=	true;
} 
private function titleWindow_close(evt:CloseEvent):void 
{ 
	model.result	=	"";
  	PopUpManager.removePopUp(this); 
}
            
public function addClient():void
{	
 	var result:Boolean	=	true;
	var resultValidate:ValidationResultEvent;			
	resultFirstName.text	=	"";
	resultLastName.text		=	"";
	resultBusiness.text		=	"";
	resultEmail.text		=	"";
				
	resultValidate	=	stringValidator.validate(firstName.text);
	if(resultValidate.type == ValidationResultEvent.INVALID)
 	{
    	result	=	false;
     	resultFirstName.text	=	
     	resultValidate.message;
	}
            	
	resultValidate	=	stringValidator.validate(lastName.text);
	if(resultValidate.type == ValidationResultEvent.INVALID)
	{
   		result	=	false;
  		resultLastName.text	=	resultValidate.message;
	}
            	
	resultValidate	=	stringValidator.validate(business.text);
	if(resultValidate.type == ValidationResultEvent.INVALID)
	{
    	result	=	false;
    	resultBusiness.text	=	resultValidate.message;
	}
            	
 	resultValidate	=	emailValidator.validate(email.text);
  	if(resultValidate.type == ValidationResultEvent.INVALID)
   	{
 		result	=	false;
   		resultEmail.text	=	resultValidate.message;
	}
            	
	model.bSubmit	=	false;
	model.result	=	"";
	if(result == true)
	{
    	var vo:ClientVO	=	new ClientVO();
            		
     	vo.firstName	=	firstName.text;
    	vo.lastName		=	lastName.text;
   		vo.business		=	business.text;
     	vo.email		=	email.text;
     	vo.message		=	message.text;

  		var event:AddClientEvent	=	new AddClientEvent(vo,model.firm.firmID);
     	CairngormEventDispatcher.getInstance().dispatchEvent( event );
 	}
	else
 	{
   		model.bSubmit	=	true;
	}
}